home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung 2 / Power-Programmierung CD 2 (Tewi)(1994).iso / gnu / gnulib / fchart / fchart.c next >
Encoding:
C/C++ Source or Header  |  1994-06-05  |  5.2 KB  |  238 lines

  1. /* fchart - fchart.c */
  2. /*
  3.  * Gnuplot code
  4.  * Copyright (C) 1986, 1987, 1990   Thomas Williams, Colin Kelley
  5.  *
  6.  * Permission to use, copy, and distribute this software and its
  7.  * documentation for any purpose with or without fee is hereby granted,
  8.  * provided that the above copyright notice appear in all copies and
  9.  * that both that copyright notice and this permission notice appear
  10.  * in supporting documentation.
  11.  *
  12.  * Permission to modify the software is granted, but not the right to
  13.  * distribute the modified code.  Modifications are to be distributed
  14.  * as patches to released version.
  15.  *
  16.  * This software  is provided "as is" without express or implied warranty.
  17.  *
  18.  *
  19.  * AUTHORS
  20.  *
  21.  *   Original Software:
  22.  *     Thomas Williams,  Colin Kelley.
  23.  *
  24.  *   Gnuplot 2.0 additions:
  25.  *       Russell Lang, Dave Kotz, John Campbell.
  26.  *
  27.  *   fchart changes and additions:
  28.  *       Piotr Filip Sawicki
  29.  *
  30.  * send your comments or suggestions to fs@uwasa.fi
  31.  *
  32.  */
  33. #include <stdio.h>
  34. #include <setjmp.h>
  35. #include <signal.h>
  36. #include "plot.h"
  37. #include "fchart.h"
  38.  
  39. #ifdef MSDOS
  40. #include <io.h>
  41. #endif
  42. #ifdef vms
  43. #include <unixio.h>
  44. #endif
  45. #ifdef __TURBOC__
  46. #include <graphics.h>
  47. #endif
  48.  
  49. /* on some compilers (Turbo C) interrupt is a reserved word
  50. #ifdef MSDOS               
  51. #define interrupt intrrtn  
  52. #endif
  53. */
  54.  
  55. char *getenv(),*strcat(),*strcpy(),*strncpy(),*sprintf();
  56.  
  57. extern char input_line[];
  58. extern FILE *outfile;
  59. extern int term;
  60. extern struct termentry term_tbl[];
  61.  
  62. #ifndef STDOUT
  63. #define STDOUT 1
  64. #endif
  65.  
  66. jmp_buf env;
  67. BOOLEAN interactive;
  68.  
  69. #ifdef vms
  70.  
  71. #define HOME "sys$login:"
  72.  
  73. #else /* vms */
  74. #ifdef MSDOS
  75.  
  76. #define HOME "FCHART"
  77.  
  78. #else /* MSDOS */
  79.  
  80. #define HOME "HOME"
  81.  
  82. #endif /* MSDOS */
  83. #endif /* vms */
  84.  
  85. #ifdef unix
  86. #define PLOTRC ".fchart"
  87. #else
  88. #define PLOTRC "fchart.ini"
  89. #endif
  90.  
  91.  
  92. #ifdef __TURBOC__
  93. void tc_interrupt()
  94. #else
  95. void inter()        /* why not void in GNUPLOT? lint cried */
  96. #endif
  97. {
  98. #ifdef MSDOS
  99. #ifdef __TURBOC__
  100.   (void) signal(SIGINT, tc_interrupt);
  101. #else
  102.     void ss_interrupt();
  103.     (void) signal(SIGINT, ss_interrupt);
  104. #endif
  105. #else
  106.     (void) signal(SIGINT, inter);
  107. #endif
  108.     (void) signal(SIGFPE, SIG_DFL);    /* turn off FPE trapping */
  109.     if (term)
  110.         (*term_tbl[term].text)();    /* hopefully reset text mode */
  111.     (void) fflush(outfile);
  112.     (void) putc('\n',stderr);
  113.     longjmp(env, TRUE);        /* return to prompt */
  114. }
  115.  
  116.  
  117. main(argc,argv)
  118. int argc;
  119. char *argv[];
  120. {
  121. /* Register the Borland Graphics Interface drivers. If they have been */
  122. /* included by the linker.                                            */
  123. #ifdef __TURBOC__
  124. registerbgidriver(CGA_driver);
  125. registerbgidriver(EGAVGA_driver);
  126. registerbgidriver(Herc_driver);
  127. #endif
  128.  
  129.     setbuf(stderr,(char *)NULL);
  130.     outfile = stdout; 
  131.  
  132.     interactive = FALSE;
  133.     init_terminal();  /* Can set term if it wishes. */
  134.  
  135. #ifdef TERM        /* set term according to predefined type */
  136.     term = change_term(TERM, strlen(TERM));
  137.     if (term < 0)
  138.         term = 0;    /* ignore error */
  139. #endif
  140.  
  141.     interactive = isatty(fileno(stdin));
  142.     if (interactive) {
  143.         show_version();
  144.         if (term != 0)
  145.             fprintf(stderr,"\tTerminal type: '%s'\n\n",term_tbl[term].name);
  146.     }
  147.  
  148.     if (!setjmp(env)) {
  149.         /* first time */
  150.         interrupt_setup();
  151.         load_rcfile();
  152.         if (argc > 1 && change_term(argv[1],strlen(argv[1])) < 1) {
  153.             interactive = 0;
  154.             int_error("wrong terminal type as option, aborted",NO_CARET);
  155.         }
  156.     } else {
  157.         /* come back here from int_error() */
  158. #ifdef vms
  159.         /* after catching interrupt */
  160.         /* VAX stuffs up stdout on SIGINT while writing to stdout,
  161.            so reopen stdout. */
  162.         if (outfile = stdout) {
  163.             if ( (stdout = freopen("SYS$OUTPUT","w",stdout))  == NULL) {
  164.                 /* couldn't reopen it so try opening it instead */
  165.                 if ( (stdout = fopen("SYS$OUTPUT","w"))  == NULL) {
  166.                     /* don't use int_error here - causes infinite loop! */
  167.                     fprintf(stderr,"Error opening SYS$OUTPUT as stdout\n");
  168.                 }
  169.             }
  170.             outfile = stdout;
  171.         }
  172. #endif                  /* VMS */
  173.         if (!interactive)
  174.             done(IO_ERROR);            /* exit on non-interactive error */
  175.     }
  176.  
  177.  
  178.     while(TRUE)
  179.         com_line();
  180.  
  181. /*    done(IO_SUCCESS);  */
  182. }
  183.  
  184.  
  185. /* Set up to catch interrupts */
  186. interrupt_setup()
  187. {
  188. #ifdef MSDOS
  189. #ifdef __TURBOC__
  190.         (void) signal(SIGINT, tc_interrupt);    /* go there on interrupt char */
  191. #else
  192.         void ss_interrupt();
  193.         save_stack();               /* work-around for MSC 4.0/MSDOS 3.x bug */
  194.         (void) signal(SIGINT, ss_interrupt);
  195. #endif
  196. #else /* MSDOS */
  197.         (void) signal(SIGINT, inter);   /* go there on interrupt char */
  198. #endif /* MSDOS */
  199. }
  200.  
  201. /* Look for a fchart start-up file */
  202. load_rcfile()
  203. {
  204.     register FILE *plotrc;
  205.     static char home[80];
  206.     static char rcfile[sizeof(PLOTRC)+80];
  207.  
  208.     /* Look for a fchart init file in . or home directory */
  209. #ifdef vms
  210.     (void) strcpy(home,HOME);
  211. #else
  212.     (void) strcat(strcpy(home,getenv(HOME)),"/");
  213. #endif                  /* vms */
  214.     (void) strcpy(rcfile, PLOTRC);
  215.     plotrc = fopen(rcfile,"r");
  216.     if (plotrc == (FILE *)NULL) {
  217.        (void) sprintf(rcfile, "%s%s", home, PLOTRC);
  218.        plotrc = fopen(rcfile,"r");
  219.     }
  220.     if (plotrc)
  221.      load_file(plotrc);
  222. }
  223.  
  224.  
  225.  
  226.  
  227.  
  228.  
  229.  
  230.  
  231.  
  232.  
  233.  
  234.  
  235.  
  236.  
  237.  
  238.